<template>
  <div v-if="needVerify">
    <p>您还未认证当前使用的邮箱{{ user.mailbox }}</p>
    <button type="button" @click="sendEmail">发送验证邮件</button>
    <p>如果您已经验证了邮件但是还看到此信息,请您刷新一下页面</p>
  </div>
  <div v-if="user.jurisdiction>= userJurisdictionLevel.USERS_JURISDICTION.level">
    您已成功认证此邮箱:{{ user.mailbox }}
  </div>
</template>
<style scoped>
/* ======== 邮箱验证容器 ======== */
div {
  width: 85%;
  max-width: 600px;
  margin: 2rem auto;
  padding: 2rem;
  border-radius: 16px;
  background: rgba(26, 26, 26, 0.35);
  backdrop-filter: blur(5%);
  box-shadow: 0 8px 30px rgba(255, 42, 109, 0.1);
  border: 1px solid rgba(255, 42, 109, 0.2);
  animation: fadeIn 0.6s ease-out;
  transition: all 0.3s ease;
  text-align: center;
}

div:hover {
  box-shadow: var(--shadow-primary);
  border-color: var(--border-primary);
}

/* ======== 未验证状态 ======== */
div[v-if="needVerify"] {
  background: rgba(40, 0, 0, 0.35);
  border-color: rgba(255, 42, 109, 0.3);
}

/* ======== 已验证状态 ======== */
div[v-if="user.jurisdiction>= userJurisdictionLevel.USERS_JURISDICTION.level"] {
  background: rgba(0, 40, 0, 0.35);
  border-color: rgba(0, 255, 0, 0.3);
}

/* ======== 段落样式 ======== */
p {
  color: var(--text-primary);
  font-size: 1.1em;
  line-height: 1.6;
  margin-bottom: 1.5rem;
}

/* ======== 邮箱地址高亮 ======== */
div[v-if="needVerify"] p:first-child {
  font-weight: 600;
  background: linear-gradient(135deg, var(--primary-red), var(--primary-purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-size: 1.2em;
}

/* ======== 提示信息 ======== */
div[v-if="needVerify"] p:last-child {
  color: var(--text-secondary);
  font-size: 0.9em;
  font-style: italic;
  margin-top: 1rem;
  padding: 0.8rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
}

/* ======== 已验证成功信息 ======== */
div[v-if="user.jurisdiction>= userJurisdictionLevel.USERS_JURISDICTION.level"] p {
  color: #4caf50;
  font-weight: 600;
  font-size: 1.2em;
  background: linear-gradient(135deg, #4caf50, #8bc34a);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ======== 按钮样式 ======== */
button {
  border-radius: 12px;
  border: 2px solid transparent;
  padding: 0.8rem 1.6rem;
  font-size: 1em;
  font-weight: 600;
  background: linear-gradient(135deg, var(--primary-red), var(--primary-purple));
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-primary);
  margin: 0.5rem 0;
}

button::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left 0.5s ease;
}

button:hover::before {
  left: 100%;
}

button:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
  border-color: var(--primary-red-light);
}

button:active {
  transform: scale(0.97);
}

/* ======== 已验证状态下的特殊样式 ======== */
div[v-if="user.jurisdiction>= userJurisdictionLevel.USERS_JURISDICTION.level"] button {
  background: var(--accent-blue);
  box-shadow: 0 4px 20px rgba(0, 168, 255, 0.3);
}

div[v-if="user.jurisdiction>= userJurisdictionLevel.USERS_JURISDICTION.level"] button:hover {
  background: var(--accent-blue-light);
  box-shadow: 0 0 12px rgba(77, 195, 255, 0.5);
}

/* ======== 响应式设计 ======== */
@media (max-width: 768px) {
  div {
    width: 90%;
    padding: 1.5rem;
    margin: 1rem auto;
  }
  
  p {
    font-size: 1em;
  }
  
  button {
    padding: 0.7rem 1.4rem;
    font-size: 0.95em;
  }
}

@media (max-width: 480px) {
  div {
    width: 95%;
    padding: 1rem;
  }
  
  p {
    font-size: 0.95em;
  }
  
  button {
    padding: 0.6rem 1.2rem;
    font-size: 0.9em;
  }
}

/* ======== 动画效果 ======== */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ======== 脉冲动画 ======== */
div[v-if="needVerify"] {
  animation: pulse-light 2s infinite alternate;
}

@keyframes pulse-light {
  0% {
    box-shadow: 0 4px 20px rgba(255, 42, 109, 0.3);
  }
  100% {
    box-shadow: 0 4px 30px rgba(255, 42, 109, 0.5);
  }
}
</style>
<script setup lang="ts">
import {getUser} from "@stores/localStorage.js";
import type {Users} from "@models/User.js";
import {ref} from "vue";
import {userJurisdictionLevel} from "@constants/userJurisdiction.js";
import axiosInstance from "@utils/axiosInstance.js";
import {globalConst} from "@constants/globalConst.js";
import ResponseResult from "@models/ReturnResult.js";

const user: Users = getUser();
const needVerify = ref<boolean>(user.jurisdiction === userJurisdictionLevel.NOT_VALIDATED.level)

async function sendEmail() {
  const r = ResponseResult.fromApiResponse((await axiosInstance.get(`${globalConst.baseUrl}user/getVerifyEmail`)).data)
  if (r.isSuccess()) {
    alert(r.msg + "," + r.returnResult)
  } else {
    alert(r.msg || "邮件发送失败,请稍后再试")
  }
}
</script>
